<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class APP_Controller extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->library('session');
		$this->load->model('Login_model', 'login');
		$method =  $this->router->method;
		define('URL', $this->config->item('base_url'));
		if( isset($this->public_methods) && array_search($method, $this->public_methods) === false && $this->login->is_logged_in() === false ){
			// method is for logged in users only
			$this->session->set_flashdata('message', "You must log in to see that.");
			$this->session->set_flashdata('login_redirect', $_SERVER['REQUEST_URI']);
			$this->redirect('users/login');
		}elseif( isset($this->admin_methods) && array_search($method, $this->admin_methods) && $this->login->is_admin() === false ){
			// method is for admins only
			$this->session->set_flashdata('message', "You must be an admin to view this page.");
			$this->session->set_flashdata('login_redirect', $_SERVER['REQUEST_URI']);
			$this->redirect('users/login');
		}else{
			
		}
		$this->pre_action($method);
	}
	
	protected function redirect($url){
		$url = URL.$url;
		header("Location: {$url}");
	}
	
	protected function pre_action($method){
	
	}


}